while getopts ":h:a:u:p:" opt
do
    case $opt in
        h)
        HOST_NAME=$OPTARG
        echo -e "\033[40;37m 您输入的主机选项$HOST_NAME\033[0m"
        ;;
        a)
        ALIAS_NAME=$OPTARG
        echo -e "\033[40;37m 您输入的主机别名$ALIAS_NAME\033[0m"
        ;;
        u)
        USER_NAME=$OPTARG
        echo -e "\033[40;37m 您输入的用户名$USER_NAME\033[0m"
        ;;
        p)
        PORT=$OPTARG
        echo -e "\033[40;37m 您输入的端口$PORT\033[0m"
        ;;
        ?)
        echo -e "\033[40;37m 未知参数,你可以这样使用 : sh upgrade.sh -s ~/${WORK_USER}/system-init -btrue -nhello -v3.0.1.3\033[0m"
        exit 1;;
    esac
done
if [[ ! -f ${HOME}/.ssh/config ]]
then
  touch ${HOME}/.ssh/config
fi
cat ${HOME}/.ssh/config | grep -E "Host\s+${HOST_NAME##*.}"
if [[ $? -ne 1 ]]
then
  #  exists , have not permission to add 
  ALIAS_NAME=${HOST_NAME}
else
  ALIAS_NAME=${HOST_NAME##*.}
fi
cat ${HOME}/.ssh/config | grep -E "HostName\s+${HOST_NAME}"

if [[ $? -eq 1 ]]
then
  echo "not found this host . . . will add ${HOST_NAME} to ssh config alias"
  content='Host '"${ALIAS_NAME}"'\n    HostName '"${HOST_NAME}"'\n    User '"${USER_NAME}"'\n    Port '"${PORT}"'\n'
  test -s ${HOME}/.ssh/config && sed -i '1i\'"${content}"'' ${HOME}/.ssh/config || echo -e $content >> ${HOME}/.ssh/config
fi
